/**
 * 
 */
package fileparse;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

/**
 * @author Leaking Fore
 *
 */
public final class FileUtil {
	
	public static long CalculateSize(File dir, String postFix, boolean bGetSub)
	{
		assert dir.isDirectory() == true;
		long nSize = 0;
		File[] files = dir.listFiles();
		for (File f : files){
			if (f.isDirectory() && bGetSub)
				nSize += CalculateSize(f, postFix, bGetSub);
			else {
				if (f.isFile() && f.getName().toLowerCase().endsWith(postFix))
					nSize += f.length();
				else
					continue;
			}
		}
		return nSize;
	}
	
	public static void clearFiles(File file, boolean clearSubs){
		if (file.isFile()) {
			file.delete();
			return;
		}
		else if (file.isDirectory() && clearSubs) {
			File[] subFiles = file.listFiles();
			for (File f : subFiles){
				FileUtil.clearFiles(f, clearSubs);
			}
		}
	}
	
	public static void parse(File inFile, File outFile, ParseInfor parseInfor, String exeName) throws IOException{
		
		long nStart = System.currentTimeMillis();
		Process process = Runtime.getRuntime().exec("..\\..\\..\\tool\\" + exeName + " " + File.separator +  
				inFile.getCanonicalPath()  + " " + File.separator + outFile.getCanonicalPath());
		parseInfor.nSpentTime = System.currentTimeMillis() - nStart;
		
	}
}
